package com.shop.dao.impl;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.shop.dao.MessageCenterDao;
import com.shop.domain.MessageCenter;
import com.shop.util.MyBatisUtil;

/**
 * 
 * @author wenjuanhenxing
 * @version V1.0 MessageCenterDaoImpl.java 2016-2-11 上午8:09:35
 */
@Repository("messageCenterDaoImpl")
public class MessageCenterDaoImpl implements MessageCenterDao {

	@Override
	public boolean addMessageCenter(MessageCenter messageCenter) {
		if (messageCenter == null) {
			return false;
		}
		SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
		int rowsAffected = sqlSession.insert(
				"com.shop.dao.mapping.MessageCenterMapper"
						+ ".addMessageCenter", messageCenter);
		MyBatisUtil.closeSession(sqlSession);
		return rowsAffected == 1;
	}

	@Override
	public boolean deleteMessageCenterById(Long id) {
		SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
		int rowsAffected = sqlSession.delete(
				"com.shop.dao.mapping.MessageCenterMapper"
						+ ".deleteMessageCenterById", id);
		MyBatisUtil.closeSession(sqlSession);
		return rowsAffected == 1;
	}

	@Override
	public boolean updateMessageStatus(MessageCenter messageCenter) {
		SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
		int rowsAffected = sqlSession.update(
				"com.shop.dao.mapping.MessageCenterMapper"
						+ ".updateMessageStatus", messageCenter);
		MyBatisUtil.closeSession(sqlSession);
		return rowsAffected == 1;
	}

}
